# pwcredis

import threading

from redis import Redis

from app.initializer import init_config


def get_redis_connection():
    # config = init_config().redis_db

    # return Redis(host='36.140.251.14', port=6379, db=0, password=123456,decode_responses=True)
    return Redis(host=init_config().redis_host, port=init_config().redis_port, db=init_config().redis_db, password=init_config().redis_password,
                 decode_responses=True)


def redis_decr(redis_key):
    lock = threading.Lock()
    lock.acquire(3)
    r = get_redis_connection()
    r.decr(redis_key, 1)
    lock.release()


def redis_incr(redis_key):
    lock = threading.Lock()
    lock.acquire(3)
    r = get_redis_connection()
    r.incr(redis_key, 1)
    lock.release()

# get_redis_connection().set("test",1)
# redis_incr("compliance")
# print(get_redis_connection().get("test"))

